package com.mifengs.commonbase.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.mifengs.commonbase.util.PreferenceUtils;
import com.mifengs.commonbase.widget.GlideCircleTransform;
import com.mifengs.commonbase.widget.GlideRoundTransform;

/**
 * Created by lihaoqi on 2017/11/4.
 */

public class ImageLoadUtil {

    public static void displayImage(Context context, String path, ImageView imageView){
        String url;
        String photoUrl = PreferenceUtils.getPhotoPath(context);
//        String photoEndUrl = PreferenceUtils.getPhotoEndPath(context);
//        if(path.endsWith("gif")){
//            url = photoUrl+path;
//        }else{
//            url = photoUrl+path+photoEndUrl;
//        }
        Glide.with(context.getApplicationContext())
                .load( photoUrl+path)
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .into(imageView);
    }

    public static void displayImage(Context context, String path, ImageView imageView,int resId ){
        String photoUrl = PreferenceUtils.getPhotoPath(context);
        Glide.with(context.getApplicationContext())
                .load(photoUrl+path)
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .placeholder(resId)
                .into(imageView);
    }


    public static void displayFitImage(Context context, String path, ImageView imageView){
        String photoUrl = PreferenceUtils.getPhotoPath(context);
        Glide.with(context.getApplicationContext())
                .load(photoUrl+path)
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .fitCenter()
                .into(imageView);
    }

    public static void glideCircleImage(Context context, String path, ImageView imageView){
        String photoUrl = PreferenceUtils.getPhotoPath(context);
        Glide.with(context.getApplicationContext())
                .load(photoUrl+path)
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .centerCrop()
                .transform(new GlideCircleTransform(context))
                .into(imageView);
    }


    public static void glideRoundImage(Context context, String path, ImageView imageView){
        String photoUrl = PreferenceUtils.getPhotoPath(context);
        Glide.with(context.getApplicationContext())
                .load(photoUrl+path)
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .centerCrop()
                .transform(new GlideRoundTransform(context,10))
                .into(imageView);
    }


}
